{% extends "base.html" %}

{% block scriptBody %}
	<script>
		function reloadRunAdd(table) {
			var dataarr = [];
			var runInfoAddData = layui.data('eventdb');
			for (var key in runInfoAddData)
				dataarr.push(runInfoAddData[key]);
			table.reload('runInfoAdd', {
				'data': dataarr
			});
		};
		layui.use(['layer', 'form', 'element', 'table'], function () {
			var layer = layui.layer,
				form = layui.form,
				element = layui.element,
				table = layui.table;
			reloadRunAdd(table);
			table.on('tool(runInfo)', function (e) {
				if (e.event == 'add') {
					var data = e.data;
					layui.data('eventdb', {
						key: data.rowkey,
						value: data
					});
					reloadRunAdd(table);
				}else if(e.event == 'detail'){
					var tablename = $('#tableName').val(),
						runs = e.data.runID;
					$.cookie('tablename', tablename);
					$.cookie('runs', runs);
					location.href = 'rundetail'
				}
			});
			table.on('tool(runInfoAdd)', function (e) {
				if (e.event == 'del') {
					var data = e.data;
					layui.data('eventdb', {
						key: data.rowkey,
						remove: true
					});
					reloadRunAdd(table);
				}else if(e.event == 'detail'){
					var tablename = $('#tableName').val(),
						runs = e.data.runID;
					$.cookie('tablename', tablename);
					$.cookie('runs', runs);
					location.href = 'rundetail'
				}
			});
			form.on('select', function(data){
				table.reload('runInfo', {
					where: {
						tablename: data.value
					}
				});
			});
			$('#viewAddedRuns').click(function(){
				$.cookie('tablename', $('#tableName').val());
				var runs = [],
					ldata = layui.data('eventdb');
				for(var key in ldata)
					runs.push(ldata[key].runID);
				$.cookie('runs', runs.join(','));
				location.href = 'rundetail';
				return false;
			})
		});
	</script>
{% endblock %}

{% block mainBody %}
	<div class="layui-container">
		<div style="width: 1084px; margin: auto;">
			<div class="layui-tab">
				<ul class="layui-tab-title">
					<li class="layui-this">
						<i class="layui-icon">&#xe62d;</i>Runs</li>
					<li>
						<i class="layui-icon">&#xe61f;</i>添加项</li>
				</ul>
				<div class="layui-tab-content">
					<div class="layui-tab-item layui-show">
						<form class="layui-form" action="" style="padding-top:15px;">
							<div class="layui-form-item">
								<label class="layui-form-label" style="text-align:center;width:auto;padding:9px 12px;">选择数据表</label>
								<div class="layui-input-inline">
									<select id="tableName" name="tableName" lay-verify="required">
										<option value="702p01-besfs3">702p01-besfs3</option>
										<option value="702-1-besfs">702-1-besfs</option>
										<option value="665p01-bes3fs-2175">665p01-bes3fs-2175</option>
										<option value="664-1-bes3fs">664-1-bes3fs</option>
										<option value="664-1-besfs2-jpsi">664-1-besfs2-jpsi</option>
										<option value="664p03-bes3fs-psip">664p03-bes3fs-psip</option>
									</select>
								</div>
							</div>
						</form>
						<table class="layui-table" lay-data="{height: 600, url:'show', page:true, id:'runInfo', limit:30, where:{tablename:'702p01-besfs3'}, request:{pageName:'pageindex', limitName:'rows'}}"
						 lay-filter="runInfo">
							<thead>
								<tr>
									<th lay-data="{field:'runID', width:100, sort:true}">Run号</th>
									<th lay-data="{field:'time', width:200, sort:true}">生成时间</th>
									<th lay-data="{field:'rowkey', width:210}">Rowkey</th>
									<th lay-data="{field:'version', width:180}">版本信息</th>
									<th lay-data="{field:'fileCount', width:120, sort:true}">dst文件个数</th>
									<th lay-data="{field:'eventCount', width:130, sort:true}">事例数量</th>
									<th lay-data="{width:120, toolbar:'#runTool'}">操作</th>
								</tr>
							</thead>
						</table>
						<script type="text/html" id="runTool">
							   <a class="layui-btn layui-btn-primary layui-btn-mini" lay-event="detail">查看</a>
							   <a class="layui-btn layui-btn-mini" lay-event="add">添加</a>
						   </script>
					</div>
					<div class="layui-tab-item">
						<div class="layui-tab-item layui-show">
							<table class="layui-table" lay-data="{page:false, id:'runInfoAdd'}" lay-filter="runInfoAdd">
								<thead>
									<tr>
										<th lay-data="{field:'runID', width:100, sort:true}">Run号</th>
										<th lay-data="{field:'time', width:200, sort:true}">生成时间</th>
										<th lay-data="{field:'rowkey', width:210}">Rowkey</th>
										<th lay-data="{field:'version', width:180}">版本信息</th>
										<th lay-data="{field:'fileCount', width:120, sort:true}">dst文件个数</th>
										<th lay-data="{field:'eventCount', width:130, sort:true}">事例数量</th>
										<th lay-data="{width:120, toolbar:'#runToolAdd'}">操作</th>
									</tr>
								</thead>
							</table>
							<script type="text/html" id="runToolAdd">
								<a class="layui-btn layui-btn-primary layui-btn-mini" lay-event="detail">查看</a>
								<a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">取消</a>
							</script>
							<a href="#" id="viewAddedRuns" class="layui-btn">查看添加项</a>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
{% endblock %}
